from time import sleep

from selenium.webdriver.common.by import By

from service.login import Login
from util.Util import BoxDriver,BasePage

class Addapp(BasePage):

    def dingwei(self):
        self.driver.click(By.XPATH, '//*[@id="s-menu-superadmin"]/button')
        self.driver.switch_to_frame_index(0)

    def addapp(self):
        self.dingwei()
        # 添加成员
        self.driver.click(By.LINK_TEXT, '添加应用')
        self.driver.input(By.ID, "name","douban")
        self.driver.input(By.ID, "abbr","db")
        self.driver.input(By.ID, "code","94066f")
        self.driver.input(By.ID, "login","https://www.douban.com")
        self.driver.click(By.ID, "submit")

    def delapp(self):
        try:
            while True:
                self.driver.click(By.XPATH,'//*[@id="categoryList"]/div[1]/div/span')
                self.driver.alert_accept()
        except Exception as e:
            print("删除完成！")


if __name__ == '__main__':
    driver = BoxDriver('Chrome')
    Login(driver).login('admin', '123456')
    addapp = Addapp(driver)
    addapp.addapp()
    addapp.delapp()
